//
//  ZHExampleMultiController1.swift
//  ZHPageView
//
//  Created by Rango on 2020/9/21.
//  Copyright © 2020 Rango. All rights reserved.
//

import UIKit

class ZHExampleMultiController1: UIViewController {

    var index: Int = 0 {
        didSet {
            print("ZHExampleMultiController -- \(index)")
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = ZHConstant.randomColor
        
        setUpUI()
    }

    func setUpUI() {
        view.backgroundColor = .white
        view.addSubview(multiPageView)
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        let multiPageViewX: CGFloat = 0
        let multiPageViewY: CGFloat = 0 
        let multiPageViewW: CGFloat = kScreenWidth()
        let multiPageViewH: CGFloat = view.frame.height - multiPageViewY
        multiPageView.frame = CGRect(x: multiPageViewX, y: multiPageViewY, width: multiPageViewW, height: multiPageViewH)
    }

    deinit {
        print("\(#file)-\(#line)-\(#function)--->销毁")
    }

    // MARK: - ---> Multi
    private lazy var multiChildVces: [UIViewController] = {
        let vc1 = ZHExampleViewController()
        vc1.title = "狩猎"
        let vc2 = ZHExampleTableController()
        vc2.title = "卧虎藏龙"
        let vc3 = ZHExampleViewController()
        vc3.title = "阿凡达"
        return [vc1, vc2, vc3]
    }()
    private lazy var multiTitles: [String] = {
        return multiChildVces.map { $0.title! }
    }()
    private lazy var style: ZHSegmentStyle = {
        $0.isGradientTitleColor = true
        $0.isShowIndicator = true
        $0.height = 32
        $0.indicatorHeight = 2
        $0.indicatorCornerRadius = 1
        return $0
    }(ZHSegmentStyle())
    private lazy var multiPageView: ZHPageView = {
        $0.didSelectedIndexClosure = { [weak self] index in
            print("didSelectedIndexClosure---\(index)")
        }
        $0.didExtraBtnActionClosure = { [weak self] item in
            guard let strongSelf = self else { return }

        }
        return $0
    }(ZHPageView(frame: .zero, style: style, titles: multiTitles, childVces: multiChildVces, parent: self))
}
